﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Addon;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
namespace Plugin
{
    public class main : CPlugin
    {
        public DForm dform = new DForm();
        public InfoForm iform = new InfoForm();
        Point last;


        public override void OnServerLoad()
        {
            ServerPrint("PlayerLoc loaded");
            try
            {
                dform.Show();
                iform.Show();
                if (dform.Created && iform.Created)
                    ServerPrint("Window Loaded");
            }
            catch
            {
                ServerPrint("DForm konnte nicht geladen werden. dafug?");
                
            }
           
        }
        public override void OnPlayerConnect(ServerClient Client)
        {
            iform.addToCombobox(Client);
        }
        public override void OnPlayerDisconnect(ServerClient Client)
        {
            iform.RemoveFromComboBox(Client);
        }

        public override void OnServerFrame()
        {
            
            List<ServerClient> cl = new List<ServerClient>();
            cl = GetClients();
            int cx = 0, cy = 0, lx= 0, ly = 0;
            int usr = 0;
            foreach (ServerClient i in GetClients())
            { usr++; }
            if (usr > 0)
            {
                foreach (ServerClient x in cl)
                {


                    dform.draw(x, new Point(cx, cy), new Point(lx, ly));
                    last.X = Convert.ToInt32(x.OriginX);
                    last.Y = Convert.ToInt32(x.OriginY);
                    if(iform.options_prntplayerlocinconsole())
                        ServerPrint("Client[" + x.ClientNum + "] " + x.Name + " X: " + cx + " Y:" + cy);
                }
            }

            iform.setMap(GetDvar("ui_mapname"));
            iform.setPlayer(usr); 
        }
    }
}
